import request from '../../../zhou-front/src/utils/request';
import type { ApiResponse, Pagination, PageResult } from '../../../zhou-front/src/types/api';
import type { AxiosResponse } from 'axios';

// 支付类型枚举
export enum PayType {
  ALIPAY = 1,
  WECHAT_PAY = 2,
  BALANCE = 3,
}

// 生成支付单 DTO
export interface PayApplyDTO {
  bizOrderNo: string; // 业务订单号，这里对应您的订单ID
  payType: PayType; // 支付类型
  amount: number; // 支付金额，单位为分
  payChannelCode: string; // 支付渠道编码
  orderInfo: string; // 订单中的商品信息，JSON字符串
}

// 支付单表单 DTO (用于余额支付)
export interface PayOrderFormDTO {
  id?: number; // 支付单ID
  // 如果余额支付还需要密码等，可以在这里添加
}

// 支付单视图对象
export interface PayOrderVO {
  id: number;
  bizOrderNo: string; // 业务订单号
  payAmount: number; // 支付金额
  payType: PayType;
  status: number; // 支付状态
  createTime: string;
  payTime: string;
}

// 支付单 DTO (用于查询详情)
export interface PayOrderDTO {
  id: number;
  bizOrderNo: string;
  payAmount: number;
  payType: PayType;
  status: number;
  createTime: string;
  payTime: string;
}

/**
 * 生成支付单
 * POST /pay-orders
 */
export function applyPayOrder(data: PayApplyDTO): Promise<AxiosResponse<ApiResponse<string>>> {
  return request({
    url: '/pay-orders',
    method: 'post',
    data: data,
  });
}

/**
 * 尝试基于用户余额支付
 * POST /pay-orders/{id}
 */
export function tryPayOrderByBalance(id: string, data: PayOrderFormDTO): Promise<ApiResponse<void>> {
  return request({
    url: `/pay-orders/${id}`,
    method: 'post',
    data: data,
  });
}

/**
 * 查询支付单列表
 * GET /pay-orders
 */
export function queryPayOrders(): Promise<AxiosResponse<ApiResponse<PayOrderVO[]>>> {
  return request({
    url: '/pay-orders',
    method: 'get',
  });
}

/**
 * 根据业务订单号查询支付单
 * GET /pay-orders/biz/{id}
 */
export function queryPayOrderByBizOrderNo(id: string): Promise<AxiosResponse<ApiResponse<PayOrderDTO>>> {
  return request({
    url: `/pay-orders/biz/${id}`,
    method: 'get',
  });
}
